package Servidor;

import org.omg.CORBA.ORB;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;
//import java.util.Properties;
import Cliente.*;

public class ServidorNTask {

    public static void main(String[] args) {
	try {
      /*//create and initialize the ORB
      Properties props = System.getProperties();
      props.put("org.omg.CORBA.ORBInitialPort", "1050");
      //Replace MyHost with the name of the host on which you are running the server
      props.put("org.omg.CORBA.ORBInitialHost", "<MyHost>");*/
      ORB orb = ORB.init(args, null);
	  System.out.println("ORB inicializado");

      //Instantiate Servant and create reference
	  POA rootPOA = POAHelper.narrow(
		  orb.resolve_initial_references("RootPOA"));
	  NTaskServerImpl ntsImpl = new NTaskServerImpl();
	  rootPOA.activate_object(ntsImpl);
	  NTaskServer ntRef = NTaskServerHelper.narrow(rootPOA.servant_to_reference(ntsImpl));
	  
      //Bind reference with NameService
	  NamingContext namingContext = NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
      System.out.println("Servicio de nombres resuelto");
      NameComponent[] nc = { new NameComponent("NTaskServer", "") };
	    namingContext.rebind(nc, ntRef);

	    //Activate rootpoa
      rootPOA.the_POAManager().activate();

      //Start readthread and wait for incoming requests
      System.out.println("Servidor listo y en ejecución ....");
  
      //REMOVE THE NEXT LINE FOR THE SIMPLER EXAMPLE
      //msImpl.startReadThread();

      orb.run();

	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}
